//
//  ProgressViewController.m
//  UITest
//
//  Created by wp w on 12-6-7.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ProgressViewController.h"
@implementation ProgressViewController

NSTimer *timer;

//定时更新process
- (void)updateProgress:(NSTimer *)sender
{
	UIProgressView *progress = [sender userInfo];
	
	//have we completed?
	if (progress.progress == 1.0)
		[timer invalidate];     //process到100%后，停止timer
	else
		progress.progress += 0.05;
}

- (void)viewDidLoad {
	
    [super viewDidLoad];
	
    //新建UIProgressView
	UIProgressView *myProgressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
	
    //设置myProgressView的frame
	CGRect progressFrame = CGRectMake(10,100,300,25);
	[myProgressView setFrame:progressFrame];
	
    //设置process的开始位置
	[myProgressView setProgress:0.0];
	
    //将myProgressView添加到self.view
	[self.view addSubview:myProgressView];
	
	[myProgressView release];
	
    //新建timer更新process
	timer = [[NSTimer scheduledTimerWithTimeInterval:0.1 
											  target:self 
											selector:@selector(updateProgress:) 
											userInfo:myProgressView 
											 repeats:YES] retain];
}


- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	
	[timer invalidate];
	[timer release];
	timer = nil;
    
    [super dealloc];
}

@end
